Skip to content

[19.0][FIX] webservice: allow to return response object on OAuth2-configure…#138

Open
Ricardoalso wants to merge 1 commit into
OCA:19.0from
camptocamp:web-api_content_only
Open

[19.0][FIX] webservice: allow to return response object on OAuth2-configure…#138
Ricardoalso wants to merge 1 commit into
OCA:19.0from
camptocamp:web-api_content_only

Conversation

@Ricardoalso
Copy link
Copy Markdown

@Ricardoalso Ricardoalso commented May 29, 2026

…d calls

When sending exchanges through an OAuth2-configured webservice.backend, the request crashed with:

TypeError: Session.request() got an unexpected keyword argument 'content_only'

Stack trace pointed to webservice/components/request_adapter.py in BackendApplicationOAuth2RestRequestsAdapter._request, where content_only was forwarded to OAuth2Session.request(...)

Also check #48


However

Defaulting content_only to True in "base.requests" seems wrong IMHO (current PR follows the same pattern)

content_only = kwargs.pop("content_only", True)

The function returns two entirely different data types depending on a boolean flag. If content_only is True, it returns a bytes object (request.content). If content_only is False, it returns a requests.Response object (request).

Because it defaults to True, a standard call to an endpoint self._request("GET", "/test") returns raw bytes instead of a typical HTTP response object. To access network metadata (such as headers or cookies), the caller must explicitly pass content_only=False. This violates the Principle of Least Astonishment.

Open question ⚠️
Should we keep the current compatibility contract for now (defaulting to bytes)? In this addon, the default behavior has historically been “bytes content”, and existing tests + doc. assert this.

Wanting raw content as the "normal" case and wanting the actual HTTP Response object as a "special context." is strange, but I don't have the full context in here. In global network programming, a Response object is the baseline rule 🤔

All of Requests’ functionality can be accessed by these 7 methods. They all return an instance of the Response object.

https://requests.readthedocs.io/en/latest/api/#main-interface

…d calls

When sending exchanges through an OAuth2-configured webservice.backend, the request crashed with:

TypeError: Session.request() got an unexpected keyword argument 'content_only'

Stack trace pointed to webservice/components/request_adapter.py in BackendApplicationOAuth2RestRequestsAdapter._request, where content_only was forwarded to OAuth2Session.request(...)
@OCA-git-bot
Copy link
Copy Markdown
Contributor

Hi @etobella,
some modules you are maintaining are being modified, check this out!

@Ricardoalso Ricardoalso changed the title [FIX] webservice: allow to return response object on OAuth2-configure… [19.0][FIX] webservice: allow to return response object on OAuth2-configure… May 29, 2026
@Ricardoalso Ricardoalso marked this pull request as draft May 29, 2026 10:00
@Ricardoalso Ricardoalso marked this pull request as ready for review May 29, 2026 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants